# 我是实现的循环数组
class MyCircularDeque(object):

    def __init__(self, k):
        self.data = [None] * k
        self.capacity = k
        self.size = 0
        # [start,end)
        self.start = 0  # 循环数组的开始节点 闭区间
        self.end = 0  # 开区间

    def resize(self, new_size):
        new_data = [None] * new_size
        for i in range(self.size):
            new_data[i] = self.data[(self.start + i) % self.capacity]
        self.data = new_data
        self.capacity = new_size
        self.start = 0
        self.end = self.size

    def insertFront(self, value):
        self.start = (self.start - 1 + self.capacity) % self.capacity
        self.data[self.start] = value
        self.size += 1
        if (self.size == self.capacity):
            new_size = self.capacity * 2
            self.resize(new_size)

    def insertLast(self, value):
        self.end = (self.end + 1 + self.capacity) % self.capacity
        self.data[self.end] = value
        self.size += 1
        if (self.size == self.capacity):
            new_size = self.capacity * 2
            self.resize(new_size)

    def deleteFront(self):
        self.data[self.start] = None
        self.start = (self.start + 1) % self.capacity
        self.size -= 1
        if (self.size != 0 and self.size == self.capacity // 4):
            self.resize(self.capacity // 2)

    def deleteLast(self):
        self.end = (self.end - 1) % self.capacity
        self.data[self.end] = None
        self.size -= 1
        if (self.size != 0 and self.size == self.capacity // 4):
            self.resize(self.capacity // 2)

    def getFront(self):
        return self.data[self.start]

    def getRear(self):
        return self.data[(self.end - 1) % self.capacity]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size == self.capacity

